%% Computing the posterior mean and variance for tau

function [bar_tau, bar_V_tau] = compute_posterior_moments(hat_theta, rep_base_se2, nu)
% INPUT: baseline study data hat_theta, reported baseline study se^2 rep_base_se2, EB estimate nu
% OUTPUT: posterior mean bar_tau, posterior variance bar_V_tau

    % Initialization
    N = size(hat_theta, 1); 
    bar_tau = zeros(N, 1);  
    bar_V_tau = zeros(N, 1);   

    for i = 1:N
        % Update the posterior variance
        bar_V_tau(i) = sum(1 ./ (nu + rep_base_se2(i, :)))^-1;      

        % Update the posterior mean
        bar_tau(i) = bar_V_tau(i) * sum(hat_theta(i, :) ./ (nu + rep_base_se2(i, :)));         
    end

end